package com.kobi.tapeRecorder;

import java.util.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class MyCallsAdapter extends ArrayAdapter<Model> {
	private final Context context;
	private List<Model> list;
	
	public MyCallsAdapter(Context context, List<Model> list) {
		super(context, R.layout.rowlayout, list);
		this.list = list;
		this.context = context;
	}
	
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		final View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
		final TextView textView2 = (TextView) rowView.findViewById(R.id.label_list_2);
		
		String myDateStr = list.get(position).getCallName().substring(1, 15);
		SimpleDateFormat curFormater = new SimpleDateFormat("yyyyMMddkkmmss");
		
		Date dateObj = new Date();
		try {
			dateObj = curFormater.parse(myDateStr);
		} catch (ParseException e) {
			e.printStackTrace();
		} 
		textView2.setText(DateFormat.getDateInstance().format(dateObj) + " " + DateFormat.getTimeInstance().format(dateObj));
		
		
		return rowView;
	}
}
